package com.artPreter.service.impl;


import com.artPreter.mapper.BannerMapper;
import com.artPreter.pojo.Banner;
import com.artPreter.service.IBannerService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 文章内容表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-12-02
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements IBannerService {

    @Override
    public IPage<Banner> getPage(Integer currentPage, Integer size, Banner banner) {
        IPage<Banner> bannerIPage = new Page<>(currentPage, size);
        LambdaQueryWrapper<Banner> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Banner::getStatus,1);
        bannerIPage = this.baseMapper.selectPage(bannerIPage, queryWrapper);
        return bannerIPage;
    }

    @Override
    public void add(Banner banner) {
        banner.setStatus(1);
        // 生成UUID并设置到实体对象中
        String uuid = UUID.randomUUID().toString();
        banner.setBannerId(uuid);
        this.baseMapper.insert(banner);
    }

    @Override
    public void edit(Banner banner) {
        this.baseMapper.updateById(banner);
    }

    @Override
    public void delete(Banner banner) {
        banner.setStatus(0);
        this.baseMapper.updateById(banner);
    }

    @Override
    public List<Banner> getList(Banner banner) {
        LambdaQueryWrapper<Banner> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Banner::getStatus,1);
        List<Banner> result= this.baseMapper.selectList(queryWrapper);
        return result;
    }
}
